/**
 * 交易API接口
 */
import api from '@/api/request'
import { v1 as uuid } from 'uuid'
let domain = ''


// 获取交易市场
export const getMarket = function (data) {
  return api.get(`${domain}api/v2/account2/market/market`, {
    cancel: false,
    cache:true,
  })
}

// 获取系统参数
export const getSysParams = function (showLoading) {
  return api.get(`${domain}api/v2/trade/sys_params`, {
    showLoading,
    cache:60,
    cancel:false
  })
}

// 市场买入和卖出
export const marketBuyorSell = function (data) {
  return api.post(`${domain}api/v2/account/entrust`, {
    data:{...data, nonce:uuid()},
    showLoading:true
  })
}

// 获取委托记录 - 当前委托、历史委托tp:0，币币成交记录tp:1
export const getCurrentEntrustByParams = function (data) {
  return api.post(`${domain}api/v2/trade/my/queryOrders`, {
    data,
    cache:true
  })
}

// 取消委托订单
export const cancelOrder = function (orderBookId) {
  return api.get(`${domain}api/v2/trade/my/orderBook/${orderBookId}/cancel`, {
    showLoading:true,
    cache:false
  })
}

// 取消当前市场\所有市场订单
export const cancelAllOrder = function (market='') {
  return api.get(`${domain}api/v2/trade/my/orderBook/cancelAll?market=${market}`, {
    showLoading:true,
    cache:false
  })
}

// 获取币种简介信息
export const getSymbolIntroduce = function (symbol='') {
  return api.get(`${domain}/api/v2/account2/market/symbolIntroduce?symbol=${symbol}`, {
    cache:60*60*24
  })
}

// 获取交易解锁任务信息
export const getTradeTaskInfo = function (symbol='') {
  return api.get(`${domain}/api/v5/user/tradeTaskInfo`, {
    cache:10
  })
}

// 获取自动交易设置
export const getBuyOrder = function (data) {
  return api.get(`${domain}/api/v5/user/tradeTaskInfo`, {
    data
  })
}